import {observable, action, runInAction} from 'mobx';
import http from '../../util/axios';

/*import { configure } from 'mobx';

// 启用严格模式 不允许在action之外修改state
configure({ enforceActions: "strict" });*/


class UserList {
    // 数据列表
    @observable public list: Table.Data[] = [];

    // 保留搜索状态
    @observable public searchStatus: Table.Values = {
        pageIndex: 1,
        pageSize: 4,
    };

    // 当前选择的用户    昵称-手机号  or 所有人
    @observable public currentSelect: string = '';

    @observable public total: number = 1;

    // 是否在加载中
    @observable public listLoading: boolean = false;

    // 当前弹窗的可见性
    @observable public modalVisible: boolean = false;

    // 加载列表
    @action public getList = async (values: Table.Values) => {
        this.listLoading = true;

        const result = await http.get('/admin/user/get/list', values);


        if (result.code !== 0) {
            runInAction(() => {
                this.listLoading = false;
            })
            return result.message;
        }
        runInAction(() => {
            const {data, total} = result.data;

            this.listLoading = false;
            this.list = data;
            this.total = total;
            this.searchStatus = values;
        })
    }


    // 设置弹框的可见性
    @action public setVisible = (visible = false) => {
        this.modalVisible = visible;
    }

    // 设置当前选中的文本可见性
    @action public setCurrentSelect = (val:string) => {
        this.currentSelect = val;
    }
}

export default new UserList();